package org.yuanqiframework.yuanqi.web.entity;

import lombok.Data;

@Data
public class AjaxResult<T> {
    private Integer code;
    private T data;
    private String message;
    private String errorMessage;

    public static <T> AjaxResult<T> success() {
        return success(null);
    }

    public static <T> AjaxResult<T> success(T data) {
        return success(data, ResponseCode.SUCCESS, ResponseMessage.SUCCESS);
    }

    public static <T> AjaxResult<T> success(T data, int code) {
        return success(data, code, ResponseMessage.SUCCESS);
    }


    public static <T> AjaxResult<T> success(T data, Integer code, String message) {
        AjaxResult<T> ajaxResult = new AjaxResult<>();
        ajaxResult.setCode(code);
        ajaxResult.setData(data);
        ajaxResult.setMessage(message);
        return ajaxResult;
    }


    public static <T> AjaxResult<T> error(String message, Integer code, T data, String errorMessage) {
        AjaxResult<T> ajaxResult = new AjaxResult<>();
        ajaxResult.setCode(code);
        ajaxResult.setData(data);
        ajaxResult.setMessage(message);
        ajaxResult.setErrorMessage(errorMessage);
        return ajaxResult;
    }

    public static <T> AjaxResult<T> error(String message, Integer code, String errorMessage) {
        return error(message, code, null, errorMessage);
    }

    public static <T> AjaxResult<T> error(String message, Integer code) {
        return error(message, code, null, null);
    }

    public static <T> AjaxResult<T> error(String message) {
        return error(message, ResponseCode.ERROR);
    }

    public static <T> AjaxResult<T> error() {
        return error(ResponseMessage.ERROR, ResponseCode.ERROR);
    }


}
